<?php
namespace app\common\exception;

use think\Controller;
use think\exception\Handle;
use think\exception\HttpException;


class Http  extends Handle
{

    ///自动跳转到首页
    public function render(\Exception $e)
    {

        if(config('app_debug')){
            ///请求异常
            if ($e instanceof HttpException && request()->isAjax()) {
                return response($e->getMessage(), $e->getStatusCode());
            }

            //可以在此交由系统处理
            return parent::render($e);
        }else{
            $html404 = <<<EOL
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=GBK">
    <title>404 Not Found</title>
</head>
<body>
    <h1>出现异常，请联系管理员！</h1>
    <span id="totalSecond">2</span>秒后自动返回
    <script language="javascript" type="text/javascript">
        <!--
        var second = document.getElementById('totalSecond').textContent;
        if (navigator.appName.indexOf("Explorer") > -1)
        {
            second = document.getElementById('totalSecond').innerText;
        } else
        {
            second = document.getElementById('totalSecond').textContent;
        }
        setInterval("redirect()", 1000);
        function redirect()
        {
            if (second < 0)
            {
                location.href = '/';
            } else
            {
                if (navigator.appName.indexOf("Explorer") > -1)
                {
                    document.getElementById('totalSecond').innerText = second--;
                } else
                {
                    document.getElementById('totalSecond').textContent = second--;
                }
            }
        }
        -->
    </script>
    <div>

    </div>
</body>
</html>
EOL;
            echo $html404;die;
        }
    }
}